<%-- 
    Document   : index
    Created on : 12-abr-2011, 13:13:22
    Author     : Sergio
--%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Inicio - appBuy</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="css/coin-slider.css" />
        <script type="text/javascript" src="js/cufon-yui.js"></script>
        <script type="text/javascript" src="js/droid_sans_400-droid_sans_700.font.js"></script>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
        <script type="text/javascript" src="js/coin-slider.min.js"></script>
    </head>
    <%@ include file="userBar.jsp" %>
    <%@ include file="topBarSlide.jsp" %>
    <%@ include file="sideBar.jsp" %>
    <%@page import="java.io.File"%>
    <%@page import="java.util.Map"%>
    <%@page import="persistence.product.ProductPersistFactory"%>
    <%@page import="persistence.product.ProductDAO"%>
    <%@page import="model.Product"%>
    <%@page import="java.util.HashMap"%>

    <div class="content">
        <div class="content_resize">
            <div class="mainbar">
                <!--<h2>Apps destacadas:</h2>-->
                <%
                            ServletConfig conf = getServletConfig();
                            ServletContext context = conf.getServletContext();
                            String persistenceMechanism = context.getInitParameter("persistenceMechanism");
                            ProductDAO persistenceManager = ProductPersistFactory.getProductDAO(persistenceMechanism);
                            Map<Integer, Product> productMap = new HashMap<Integer, Product>();
                            int pagina = 1;
                            if (request.getParameter("pagina") != null) {
                                pagina = Integer.parseInt(request.getParameter("pagina"));
                            }
                            int tam = persistenceManager.readPageProducts(productMap, "Windows Phone", pagina);
                            for (int i = 1; i <= productMap.size(); i++) {
                                request.setAttribute("product", productMap.get(i));
                %>
                <jsp:useBean id="product" scope="request" class="model.Product" />
                <div class="article">
                    <h2><span><jsp:getProperty name="product" property="nombre" /></span></h2>
                    <p class="infopost">Añadida <span class="date">el <jsp:getProperty name="product" property="fecha" /></span> por <a href="/Appbuy/FrontController?form=readUserServlet&userName=<jsp:getProperty name="product" property="usuario" />"><jsp:getProperty name="product" property="usuario" /></a><a href="#" class="com"><b>Precio: <span><jsp:getProperty name="product" property="precio" /> €</span></b></a></p>
                    <div class="clr"></div>
                    <div class="post_content"><br>
                        <b>· Sistema Operativo:</b> <jsp:getProperty name="product" property="so" /><br><br>
                        <b>· Ventas:</b> <jsp:getProperty name="product" property="ventas" /><br><br>
                        <b>· Breve descripcion:</b> <jsp:getProperty name="product" property="descripcionc" /><br><br>
                        <b> · Descripcion:</b> <jsp:getProperty name="product" property="descripcionl" /><br><br>
                    </div>
                    <%

                                String path = request.getServletContext().getRealPath("../../web") + "/images\\APP_" + product.getNombre() + '_' + product.getSo() + ".jpg";
                                File f = new File(path);
                                if (f.exists()) {
                    %>
                    <div class="img"><img src="images/APP_<jsp:getProperty name="product" property="nombre" />_<jsp:getProperty name="product" property="so" />.jpg" width="150" height="150" alt="" class="fl" /></div>
                        <%} else {%>
                    <div class="img"><img src="images/OS_<jsp:getProperty name="product" property="so" />.png" width="150" height="150" alt="" class="fl" /></div>
                        <%}%>
                    <p class="spec"><a href="/Appbuy/FrontController?form=addToCarritoServlet&nombre=<jsp:getProperty name="product" property="id" />" class="rm">AL CARRITO</a></p>
                    <div class="clr"></div>
                </div>
                <%}
                            int totPaginas = (int) tam / 2;
                            if (tam % 2 != 0) {
                                totPaginas++;
                            }
                %>
                <p class="pages">
                    <%if (tam == 0) {%>
                <h2>No hay aplicaciones para Windows Phone!</h2>
                <%} else if (pagina == 1 && totPaginas == 1) {%>
                <small>Página <%=pagina%> de <%=totPaginas%></small> <span><%=pagina%></span>
                <%} else if (pagina == 1 && totPaginas != 1) {%>
                <small>Página <%=pagina%> de <%=totPaginas%></small> <span><%=pagina%></span> <a href="main_WindowsPhone.jsp?pagina=<%=pagina + 1%>"><%=pagina + 1%></a> <a href="main_WindowsPhone.jsp?pagina=<%=totPaginas%>">&raquo;</a>
                <%} else if (pagina == totPaginas) {%>
                <small>Página <%=pagina%> de <%=totPaginas%></small> <a href="main_WindowsPhone.jsp?pagina=1">&laquo</a> <a href="main_WindowsPhone.jsp?pagina=<%=pagina - 1%>"><%=pagina - 1%></a> <span><%=pagina%></span>
                <%} else {%>
                <small>Página <%=pagina%> de <%=totPaginas%></small> <a href="main_WindowsPhone.jsp?pagina=1">&laquo</a> <a href="main_WindowsPhone.jsp?pagina=<%=pagina - 1%>"><%=pagina - 1%></a> <span><%=pagina%></span> <a href="main_WindowsPhone.jsp?pagina=<%=pagina + 1%>"><%=pagina + 1%></a> <a href="main_WindowsPhone.jsp?pagina=<%=totPaginas%>">&raquo</a>
                <%}%>
            </div>
            <div class="clr"></div>
        </div>
    </div>
    <%@ include file="bottomBar.jsp" %>
</html>